package com.wiz.data.vo.to;

/**
 * 抽象报文消息域
 * @author Hakeny
 */
public abstract class MessageFiled implements Cloneable {
	protected final String addLength = "000";

	protected int index;// 域号
	protected int type;
	protected Object value;// 值
	protected int needLength;// 转换后的长度值，默认4字节

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public Object getValue() {
		return value;
	}

	public void setValue(Object value) {
		this.value = value;
	}

	public int getNeedLength() {
		return needLength;
	}

	public void setNeedLength(int needLength) {
		this.needLength = needLength;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	/**
	 * 转换为byte[]
	 * 
	 * @return
	 */
	public abstract byte[] toBytes();

	// protected byte[] toBcd(byte[] val){
	// byte[] finalValue = new byte[val.length / 2];
	// for (int i = 0; i < finalValue.length; i++) {
	// byte temp1 = (byte) (val[i * 2] < 0x30 ? val[i * 2] : val[i * 2] - 0x30);
	// //
	// byte temp2 = (byte) (val[i * 2 + 1] < 0x30 ? val[i * 2 + 1] : val[i * 2 +
	// 1] - 0x30);
	// finalValue[i] = (byte) (((temp1 << 4) & 0xFF) // 前4位
	// | ((temp2 & 0x0F) & 0xFF)); // 后4位
	// }
	// return finalValue;
	// }

}
